package com.stadium.servlet.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.stadium.bean.Order;
import com.stadium.repository.OrderRepository;
import com.stadium.servlet.OrderServlet;

@Service(value = "OrderServlet")
public class OrderServletImpl implements OrderServlet {

	@Autowired
	private OrderRepository orderRepository;

	//保存用户订单信息
	@Transactional
	public void save(Order order) {
		orderRepository.saveAndFlush(order);
	}
	
	//返回 status状态（审核或未审核） 订单信息
	@Transactional(readOnly = true)
	public List<Order> getAll(Integer status){
		return orderRepository.findAll(status);
	}

	//根据id删除对应的订单信息
	@Transactional
	public void delete(Integer id) {
		orderRepository.delete(id);
	}

	//根据订单编号修改订单状态
	@Transactional(readOnly = true)
	public Order getById(Integer id) {
		return orderRepository.findOne(id);
	}

	//根据用户账号查询相关未归还器材订单信息
	@Transactional(readOnly = true)
	public List<Order> getByAccount(String account) {
		return orderRepository.findAll(account);
	}

	//获取用户申请归还器材的对应信息
	@Transactional(readOnly = true)
	public List<Order> getAllApplyOrder() {
		return orderRepository.getAllApplyOrder();
	}
}
